/**
 * @Author       : Hejh(3010733382@qq.com)
 * @Version      : V1.0
 * @Date         : 2024-01-18 16:58:59
 * @Description  : 计划任务接口路由
 */
const Router = require('koa-router')
const { verifyToken } = require('@/utils/jwt')
const { verifyAuth } = require('@/middlewares/authMiddlewares/verifyAuth')
const scheduleTaskValidate = require('@/middlewares/validateMiddlewares/scheduleTaskValidate')
const {
  validateSlideCode
} = require('@/middlewares/validateMiddlewares/userValidate')
const scheduleTaskController = require('@/controller/scheduleTaskController')

const router = new Router()

/**
 * 获取计划任务列表
 */
router.get(
  '/list',
  verifyToken(),
  verifyAuth(['admin.schedule.list']),
  scheduleTaskValidate.listScheduleTaskValidate,
  scheduleTaskController.listScheduleTask
)

/**
 * 创建计划任务列表
 */
router.post(
  '/create',
  verifyToken(),
  verifyAuth(['admin.schedule.edit']),
  scheduleTaskValidate.createScheduleTaskValidate,
  scheduleTaskController.createScheduleTask
)

/**
 * 更新计划任务列表
 */
router.put(
  '/update',
  verifyToken(),
  verifyAuth(['admin.schedule.edit']),
  scheduleTaskValidate.updateScheduleTaskValidate,
  scheduleTaskController.updateScheduleTask
)

/**
 * 删除计划任务列表
 */
router.delete(
  '/delete',
  validateSlideCode(),
  verifyToken(),
  verifyAuth(['admin.schedule.edit']),
  scheduleTaskValidate.delScheduleTasksValidate,
  scheduleTaskController.delScheduleTasks
)

/**
 * 计划任务排序
 */
router.put(
  '/sort',
  verifyToken(),
  verifyAuth(['admin.schedule.edit']),
  scheduleTaskValidate.sortScheduleTasksValidate,
  scheduleTaskController.sortScheduleTasks
)

/**
 * 计划任务运行接口
 */
router.post(
  '/run',
  verifyToken(),
  verifyAuth(['admin.schedule.edit']),
  scheduleTaskValidate.runScheduleTaskValidate,
  scheduleTaskController.runScheduleTask
)

module.exports = router
